import 'package:business_boost/bridge/boost_bridge.dart';
import 'package:business_boost/bridge/boost_bridge_impl.dart';
import 'package:flutter/material.dart';
import 'package:lib_core/bridge/common_bridge.dart';
import 'package:lib_core/ext/string_ext.dart';
import 'package:lib_core/lib_core.dart';
import 'package:lib_ui/lib_ui.dart';

class BoostMainPage extends StatefulWidget {
  Map<String, dynamic>? argument;

  BoostMainPage({super.key, this.argument});

  @override
  State<BoostMainPage> createState() => _BoostMainPageState();
}

class _BoostMainPageState extends State<BoostMainPage> {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      '收到原生带过来的数据:${widget.argument}'.showSuccess();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TransparentAppBar(
        title: 'FlutterBoost调试页',
      ),
      body: Container(
        alignment: Alignment.center,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            TextButton(
              onPressed: () {
                BoostHostApi().showNativeTransparentDialog('');
              },
              child: Text(
                '展示原生透明弹窗',
                style: LDFont.regular(),
              ),
            ),
            TextButton(
              onPressed: () {
                if (widget.argument?['pigeon'] == true) {
                  BoostNavigator.instance.pop({'name': 'pigeon dog'});
                } else {
                  BoostNavigator.instance.pop({'name': 'boost dog'});
                }
              },
              child: Text(
                '返回数据给原生',
                style: LDFont.regular(),
              ),
            ),
            TextButton(
              onPressed: () async {
                bool? ok = await DialogHostApi().showNativeNormalDialog('原生', '普通弹窗');
                if (ok == true) {
                  '原生点击了确定'.showSuccess();
                } else {
                  '原生点击了取消'.showSuccess();
                }
              },
              child: Text(
                '显示原生普通弹窗',
                style: LDFont.regular(),
              ),
            ),
            TextButton(
              onPressed: () async {
                String? ok = await DialogHostApi().showNativeInputDialog('原生', '输入弹窗', '默认值');
                '原生返回的数据：$ok'.showSuccess();
              },
              child: Text(
                '显示原生输入弹窗',
                style: LDFont.regular(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
